home *** CD-ROM | disk | FTP | other *** search
Wrap
VERSION 2.00 Begin Form frmMain BackColor = &H00C0C0C0& Caption = "Programatic Database Creation" ClientHeight = 3600 ClientLeft = 1230 ClientTop = 2460 ClientWidth = 6150 Height = 4005 Left = 1170 LinkTopic = "Form1" MaxButton = 0 'False MinButton = 0 'False ScaleHeight = 3600 ScaleWidth = 6150 Top = 2115 Width = 6270 WindowState = 2 'Maximized Begin CheckBox Check2 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Version 1.0:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 495 Left = 5400 TabIndex = 2 Top = 1140 Width = 1335 End Begin CheckBox Check1 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Encrypted:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 495 Left = 5520 TabIndex = 1 Top = 600 Width = 1215 End Begin CommandButton Command2 Caption = "Translate" Height = 495 Left = 4740 TabIndex = 3 Top = 1860 Width = 1215 End Begin CommandButton Command1 Caption = "Set Names" Height = 495 Left = 3420 TabIndex = 0 Top = 1860 Width = 1215 End Begin CommonDialog SaveDlg DialogTitle = "Output File" Left = 9060 Top = 4800 End Begin CommonDialog OpenDlg DialogTitle = "Choose an Access Database" InitDir = "c:\" Left = 9060 Top = 5400 End Begin Line Line2 BorderWidth = 3 Index = 2 X1 = 7920 X2 = 7920 Y1 = 3720 Y2 = 2700 End Begin Line Line2 BorderWidth = 3 Index = 1 X1 = 1320 X2 = 1320 Y1 = 3720 Y2 = 2700 End Begin Line Line2 BorderWidth = 3 Index = 0 X1 = 1320 X2 = 7920 Y1 = 3720 Y2 = 3720 End Begin Line Line1 BorderWidth = 3 X1 = 1320 X2 = 7920 Y1 = 2700 Y2 = 2700 End Begin Label FileName BackColor = &H00E0E0E0& Height = 255 Left = 3420 TabIndex = 17 Top = 2820 Width = 3015 End Begin Label Label8 BackColor = &H00C0C0C0& Caption = "Status of:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 375 Left = 2460 TabIndex = 16 Top = 2820 Width = 915 End Begin Label Label7 Alignment = 2 'Center BackColor = &H00E0E0E0& BorderStyle = 1 'Fixed Single Caption = "Use the 'Set Names' button to assign the input/output filenames, then use the 'Translate' button to create the text file that contains the database definitions for the input database you chose. This is a quick and dirty utility... sorry it ain't pretty." FontBold = 0 'False FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = 0 'False Height = 495 Left = 120 TabIndex = 15 Top = 3960 Width = 9315 End Begin Label Label6 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Indexes:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 315 Left = 5700 TabIndex = 9 Top = 3360 Width = 855 End Begin Label Label5 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Fields:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 315 Left = 3600 TabIndex = 14 Top = 3360 Width = 855 End Begin Label Label4 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Tables:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 255 Left = 1500 TabIndex = 13 Top = 3360 Width = 855 End Begin Label TxtTables BackColor = &H00C0C0C0& Height = 255 Left = 2400 TabIndex = 12 Top = 3360 Width = 1095 End Begin Label TxtFields BackColor = &H00C0C0C0& Height = 315 Left = 4500 TabIndex = 11 Top = 3360 Width = 1095 End Begin Label TxtIndexes BackColor = &H00C0C0C0& Height = 315 Left = 6600 TabIndex = 10 Top = 3360 Width = 1095 End Begin Label OutputName BackColor = &H00E0E0E0& Height = 255 Left = 6000 TabIndex = 8 Top = 300 Width = 3015 End Begin Label InputName BackColor = &H00E0E0E0& Height = 255 Left = 1500 TabIndex = 7 Top = 300 Width = 3015 End Begin Label Label3 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Output Name:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 315 Left = 4740 TabIndex = 6 Top = 300 Width = 1215 End Begin Label Label2 Alignment = 1 'Right Justify BackColor = &H00C0C0C0& Caption = "Input Name:" FontBold = -1 'True FontItalic = 0 'False FontName = "MS Sans Serif" FontSize = 8.25 FontStrikethru = 0 'False FontUnderline = -1 'True Height = 315 Left = 240 TabIndex = 5 Top = 300 Width = 1215 End Begin Label Label1 Alignment = 2 'Center BackColor = &H00C0C0C0& Caption = "This program is provided FREE of charge from Dirigible Software. Neither Dirigible Software nor employees of Dirigible Software accepts any responsibility for any damage that this program might cause. Use at your own risk! Comments and Questions WILL be responded to by leaving the appropriate information at (310) 614-9466 or through e-mail at PROGRAM396@AOL.COM. Source code available upon request." Height = 915 Left = 60 TabIndex = 4 Top = 5940 Width = 9495 End Dim FNum% Dim OutFile$ Sub AddLine (Text$) If FNum% = -1 Then ' Poor error checking... If OutFile$ = "" Then Exit Sub FNum% = FreeFile ' No error checking... Open OutFile For Output As FNum% End If Print #FNum%, Text$ End Sub ' Copyright: Dirigible Software, 1993-1994. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Check for file existence. ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' CHANGE HISTORY '---------------------------------------------------------------------------- ' Date | Description | Inits. '---------------------------------------------------------------------------- ' 08/15/93| Created. | RDTIII '---------------------------------------------------------------------------- ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' Function CheckFile% (FName$) Dim FileCheck$, retval% retval% = True On Error Resume Next FileCheck$ = Dir$(FName$) If FileCheck$ = "" Then retval% = False End If CheckFile% = retval% End Function Sub Command1_Click () ' Provide a common dialog for file selection frmMain.OpenDlg.Filename = "" frmMain.OpenDlg.Flags = OFN_READONLY frmMain.OpenDlg.Filter = "Access Databases |*.MDB" frmMain.OpenDlg.Action = 1 If Not CheckFile((frmMain.OpenDlg.Filename)) Then Exit Sub frmMain.InputName.Caption = UCase(frmMain.OpenDlg.Filename) frmMain.SaveDlg.Filename = "" ' Loop on replace fail SaveDlg: frmMain.SaveDlg.Filter = "Text Files |*.TXT" frmMain.SaveDlg.Action = 2 ' Anything? (not the most efficient way, I know...) If frmMain.SaveDlg.Filename = "" Then Exit Sub If CheckFile((frmMain.SaveDlg.Filename)) Then If (MsgBox("Replace existing file?", 1 Or 48 Or 4096) <> 1) Then GoTo SaveDlg End If OutFile$ = frmMain.SaveDlg.Filename frmMain.OutputName.Caption = UCase(frmMain.SaveDlg.Filename) End Sub Sub Command2_Click () ' Vars. Dim DB As database ' Primary DB component Dim TB As tabledef ' " Dim FD As Field ' " Dim IDX As Index ' " Dim DBName$ ' DB Name (duh) Dim DBColl% ' DB Collating order Dim Options& ' DB Options (Version &&/|| Encrypted) Dim Encrypt%, Version% ' ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Dim TBName$ ' Table name, as it was read Dim FDName$ ' Field name, " Dim IDXName$ ' Index name, " Dim TCnt% ' Number of tables in DB Dim FDCnt% ' Number of fields per table Dim IDXCnt% ' Number of indexes per table Dim i%, j% ' Loop vars. Static UTbl%, UFld%, UIDX% ' # processed Const OFN_READONLY = &H1& ' Quick check... If frmMain.InputName.Caption = "" Or frmMain.OutputName.Caption = "" Then Exit Sub frmMain.MousePointer = 11 frmMain.Filename.Caption = frmMain.InputName.Caption frmMain.TxtTables.Caption = UTbl% frmMain.TxtFields.Caption = UFld% frmMain.TxtIndexes.Caption = UIDX% DoEvents ' No time for error checking...! Set DB = OpenDatabase(frmMain.OpenDlg.Filename) ' Count the number tables (includes system tables) TCnt% = DB.TableDefs.Count - 1 DBName$ = DB.Name DBColl% = DB.CollatingOrder ' Create the header AddLine "" AddLine "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine "' Programatic database creation procedure. '" AddLine "' '" AddLine "' Dirigible Software - R. Donald Thompson, III '" AddLine "' Version: November 1993 '" AddLine "' Questions or Comments: (310) 614-9466 / PROGRAM396@AOL.COM" '" AddLine "' '" AddLine "'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine "'" AddLine "' Database: " & frmMain.OpenDlg.Filetitle AddLine "' Tables : " & TCnt% - 5 AddLine "' Date : " & Now AddLine "'" AddLine "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine "Function DBCreate" & Left$(frmMain.OpenDlg.Filetitle, Len(frmMain.OpenDlg.Filetitle) - 4) & "() As Integer" AddLine "" AddLine " DBCreate = True ' Return value." AddLine "" AddLine " Dim DB As Database ' Database to create." AddLine "" ' Generic stuff... AddLine " ' You will probably want to add error handling here, and set the return" AddLine " ' value accordingly on failure, etc., i.e.," AddLine " ' If FileExist(" & Chr(34) & DBName & Chr(34) & ") then" AddLine " ' Kill " & Chr(34) & DBName & Chr(34) AddLine " ' ..." AddLine " ' Endif" AddLine "" AddLine " ' Create the database..." ' Define/establish options Encrypt% = IIf(frmMain.Check1 <> 0, 2, 0) Version% = IIf(frmMain.Check2 <> 0, 1, 0) ' 'and' them together, regardless... Options& = Encrypt% + Version% '----------------------------------- ' NOTE: LangID... -> HARD-CODED! '----------------------------------- If Options& <> 0 Then AddLine " Set db = CreateDatabase(" & Chr(34) & DBName$ & Chr(34) & ", " & Chr(34) & ";LANGID=0x0809;CP=1252;COUNTRY=0" & Chr(34) & ", " & Options& & ")" Else AddLine " Set db = CreateDatabase(" & Chr(34) & DBName$ & Chr(34) & ", " & Chr(34) & ";LANGID=0x0809;CP=1252;COUNTRY=0" & Chr(34) & ")" End If AddLine "" ' Loop for all of the tables in the DB For i% = 0 To TCnt% Set TB = DB(i%) TBName$ = TB.Name ' System table? If Left$(TBName$, 4) <> "MSys" Then UTbl% = UTbl% + 1 frmMain.TxtTables.Caption = UTbl% AddLine "" AddLine "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine " ' Table: " & UCase(TBName) FDCnt% = TB.Fields.Count AddLine " ' Number of fields: " & FDCnt% IDXCnt% = TB.Indexes.Count AddLine " ' Number of indexes: " & IDXCnt% AddLine "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine "" AddLine " Dim Tbl" & UTbl% & " As New TableDef" AddLine "" AddLine " ' Set the table name..." AddLine " Tbl" & UTbl% & ".Name = " & Chr(34) & UCase(TBName$) & Chr(34) AddLine "" AddLine " ' Build Tables..." AddLine "" ' Loop for all of the tables For j = 0 To FDCnt% - 1 UFld% = UFld% + 1 frmMain.TxtFields.Caption = UFld% Set FD = TB.Fields(j) AddLine " Dim Fld" & UFld & " As New Field" AddLine " Fld" & UFld% & ".Name = " & Chr(34) & FD.Name & Chr(34) AddLine " Fld" & UFld% & ".Type = " & FD.Type AddLine " Fld" & UFld% & ".Size = " & FD.Size AddLine " Fld" & UFld% & ".Attributes = " & FD.Attributes AddLine " Tbl" & UTbl% & ".Fields.Append " & "Fld" & UFld% AddLine "" Next AddLine " ' Build Indexes..." AddLine "" ' Loop for all of the indexes For j% = 0 To IDXCnt% - 1 UIDX% = UIDX% + 1 frmMain.TxtIndexes.Caption = UIDX% DoEvents Set IDX = TB.Indexes(j%) AddLine " Dim Idx" & UIDX & " As New Index" AddLine " Idx" & UIDX% & ".Name = " & Chr(34) & IDX.Name & Chr(34) AddLine " Idx" & UIDX% & ".Primary= " & IDX.Primary AddLine " Idx" & UIDX% & ".Unique = " & IDX.Unique AddLine " Idx" & UIDX% & ".Fields = " & Chr(34) & IDX.Fields & Chr(34) AddLine " Tbl" & UTbl% & ".Indexes.Append " & "Idx" & UIDX% AddLine "" Next AddLine "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine "' Create table: " & UCase(TBName$) & "..." AddLine "''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''" AddLine " DB.TableDefs.Append Tbl" & UTbl% End If Next AddLine "" AddLine " ' End of database translation." AddLine " ' ----------------------------" AddLine " ' Total Tables : " & UTbl% AddLine " ' Total Fields : " & UFld% AddLine " ' Total Indexes : " & UIDX% AddLine "" AddLine "End Sub" Close #FNum% FNum% = 0 frmMain.InputName.Caption = "" frmMain.OutputName.Caption = "" frmMain.TxtTables.Caption = UTbl% frmMain.TxtFields.Caption = UFld% frmMain.TxtIndexes.Caption = UIDX% UTbl% = 0 UFld% = 0 UIDX% = 0 frmMain.MousePointer = 0 End Sub Sub Form_Load () FNum% = -1 End Sub